# Maintainer: Morten Linderud <foxboron@archlinux.org>
# Maintainer: Bartłomiej Piotrowski <bpiotrowski@archlinux.org>

pkgname=skopeo
pkgver=1.12.0
pkgrel=1
pkgdesc='A command line utility for various operations on container images and image repositories.'
arch=(loong64 x86_64)
url='https://github.com/containers/skopeo'
license=(APACHE)
depends=(gpgme device-mapper containers-common)
makedepends=(go go-md2man btrfs-progs git systemd)
_commit=a55290973794d93f602a027e795bf510bd3cad01       #refs/tags/v1.12.0
source=(git+$url#commit=$_commit)
sha256sums=('SKIP')

pkgver() {
  cd ${pkgname}
  git describe --tags | sed 's/^v//;s/-/+/g'
}

prepare(){
  cd ${pkgname}
  sed -i 's|.PHONY: bin/skopeo||' Makefile
  sed -i 's|-gcflags "$(GOGCFLAGS)"||' Makefile
}

build() {
  cd ${pkgname}
  export CGO_LDFLAGS="${LDFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  make bin/skopeo GO_DYN_FLAGS="-buildmode=pie -trimpath" BUILDTAGS='containers_image_ostree_stub'
  make docs
}

package() {
  cd $pkgname
  make DESTDIR="${pkgdir}" PREFIX="/usr" install
  rm -rf "${pkgdir}/etc/containers/registries.d"
  rm "${pkgdir}/etc/containers/policy.json"
}
